home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / SideScroller / SideScrollerManager.as < prev    next >
Text File  |  2007-09-27  |  5KB  |  176 lines

  1. class SideScroller.SideScrollerManager extends Library.DispatcherBase
  2. {
  3.    static var LOOP_BUFFER = 150;
  4.    static var SCROLL_ONE_WAY = 1;
  5.    static var SCROLL_BOTH_SIDE = 2;
  6.    static var ONE_WAY_CAMERA_BUFFER = 120;
  7.    function SideScrollerManager(__mcRef, __nStageWidth, __nStageHeight, __oParentObject)
  8.    {
  9.       super();
  10.       this.mcRef = __mcRef;
  11.       this.oParentObject = __oParentObject;
  12.       SideScroller.Ground.doClean();
  13.       SideScroller.SideScrollerManager._oCtrl = this;
  14.       this.aLayers = new Array();
  15.       this.nCurrentPosition = 0;
  16.       this.bAutoScroll = false;
  17.       this.nNextDepth = 0;
  18.       this.nStageWidth = __nStageWidth;
  19.       this.nStageHeight = __nStageHeight;
  20.       this.oCamera = new SideScroller.BasicCamera(this.nStageWidth,this.nStageHeight,this);
  21.       this.oParentObject.doAddListener(this);
  22.    }
  23.    static function get Instance()
  24.    {
  25.       return SideScroller.SideScrollerManager._oCtrl;
  26.    }
  27.    function doEnterFrame()
  28.    {
  29.       super.doEnterFrame();
  30.       this.doMoveLayers();
  31.    }
  32.    function doAddLayer(__oLayerID, __nLayerType, __nAttachMethod)
  33.    {
  34.       var _loc3_ = this.mcRef.createEmptyMovieClip(__oLayerID.toString() + "_" + this.nNextDepth,this.nNextDepth);
  35.       var _loc2_ = new SideScroller.Layer(__oLayerID,_loc3_,__nLayerType,__nAttachMethod,this);
  36.       this.aLayers.push(_loc2_);
  37.       this.nNextDepth = this.nNextDepth + 1;
  38.       return _loc2_;
  39.    }
  40.    function setScrollSpeed(__nScrollSpeed)
  41.    {
  42.       this.nScrollSpeed = __nScrollSpeed;
  43.    }
  44.    function setScrollMethod(__nScrollMethod)
  45.    {
  46.       this.nScrollMethod = __nScrollMethod;
  47.    }
  48.    function setDefaultLayer(__oLayerID)
  49.    {
  50.       this.oDefaultLayerId = __oLayerID;
  51.    }
  52.    function getLayer(__oLayerID)
  53.    {
  54.       var _loc3_ = undefined;
  55.       var _loc2_ = undefined;
  56.       _loc2_ = 0;
  57.       while(_loc2_ <= this.aLayers.length - 1)
  58.       {
  59.          if(this.aLayers[_loc2_].Id == __oLayerID)
  60.          {
  61.             _loc3_ = this.aLayers[_loc2_];
  62.          }
  63.          _loc2_ = _loc2_ + 1;
  64.       }
  65.       return _loc3_;
  66.    }
  67.    function getLayerFor(__mcObject)
  68.    {
  69.       var _loc3_ = undefined;
  70.       var _loc2_ = undefined;
  71.       _loc2_ = 0;
  72.       while(_loc2_ <= this.aLayers.length - 1)
  73.       {
  74.          if(String(__mcObject).indexOf(String(this.aLayers[_loc2_].Ref)) != -1)
  75.          {
  76.             _loc3_ = this.aLayers[_loc2_];
  77.          }
  78.          _loc2_ = _loc2_ + 1;
  79.       }
  80.       return _loc3_;
  81.    }
  82.    function doAddStaticObject(__mcObject)
  83.    {
  84.       var _loc2_ = this.getLayerFor(__mcObject);
  85.       var _loc3_ = new SideScroller.StaticObject(__mcObject,_loc2_);
  86.    }
  87.    function doDestroy()
  88.    {
  89.       this.oParentObject.doRemoveListener(this);
  90.       this.oCamera.doDestroy();
  91.       delete this.oCamera;
  92.       delete SideScroller.SideScrollerManager._oCtrl;
  93.       delete this.oParentObject;
  94.       for(var _loc3_ in this.aLayers)
  95.       {
  96.          this.aLayers[_loc3_].doDestroy();
  97.       }
  98.       super.doDestroy();
  99.    }
  100.    function get Active()
  101.    {
  102.       return !this.bPaused;
  103.    }
  104.    function get StageWidth()
  105.    {
  106.       return this.nStageWidth;
  107.    }
  108.    function get StageHeight()
  109.    {
  110.       return this.nStageHeight;
  111.    }
  112.    function get ScrollMethod()
  113.    {
  114.       return this.nScrollMethod;
  115.    }
  116.    function get CameraManager()
  117.    {
  118.       return this.oCamera;
  119.    }
  120.    function get Limits()
  121.    {
  122.       var _loc4_ = new Object();
  123.       var _loc3_ = undefined;
  124.       var _loc2_ = undefined;
  125.       _loc2_ = 0;
  126.       while(_loc2_ <= this.aLayers.length - 1)
  127.       {
  128.          if(this.aLayers[_loc2_].Id == this.oDefaultLayerId)
  129.          {
  130.             _loc3_ = this.aLayers[_loc2_];
  131.          }
  132.          _loc2_ = _loc2_ + 1;
  133.       }
  134.       _loc4_.left = 0;
  135.       _loc4_.right = _loc3_.PanelsWidth;
  136.       _loc4_.top = 0;
  137.       _loc4_.bottom = _loc3_.PanelsHeight;
  138.       return _loc4_;
  139.    }
  140.    function doMoveLayers()
  141.    {
  142.       var _loc2_ = undefined;
  143.       _loc2_ = 0;
  144.       while(_loc2_ <= this.aLayers.length - 1)
  145.       {
  146.          if(this.nScrollMethod == SideScroller.SideScrollerManager.SCROLL_ONE_WAY)
  147.          {
  148.             var _loc3_ = this.nCurrentPosition;
  149.             this.nCurrentPosition = Math.min(this.nCurrentPosition,this.oCamera.__get__PosX());
  150.             if(this.nCurrentPosition < this.oCamera.__get__PosX() - SideScroller.SideScrollerManager.ONE_WAY_CAMERA_BUFFER)
  151.             {
  152.                this.nCurrentPosition = this.oCamera.__get__PosX() - SideScroller.SideScrollerManager.ONE_WAY_CAMERA_BUFFER;
  153.             }
  154.             else if(this.bAutoScroll)
  155.             {
  156.                this.nCurrentPosition -= this.nScrollSpeed;
  157.             }
  158.             if(this.nCurrentPosition < - (this.__get__Limits().right - this.nStageWidth))
  159.             {
  160.                this.nCurrentPosition = - (this.__get__Limits().right - this.nStageWidth);
  161.             }
  162.             if(this.nCurrentPosition > _loc3_)
  163.             {
  164.                this.nCurrentPosition = _loc3_;
  165.             }
  166.          }
  167.          else
  168.          {
  169.             this.nCurrentPosition = this.oCamera.PosX;
  170.          }
  171.          this.aLayers[_loc2_].doMoveTo(this.nCurrentPosition,this.oCamera.__get__PosY());
  172.          _loc2_ = _loc2_ + 1;
  173.       }
  174.    }
  175. }
  176.